Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix line drawing during IME operations. #6223

Merged
6 commits merged into from
Jun 3, 2020
Merged

Fix line drawing during IME operations. #6223

6 commits merged into from
Jun 3, 2020

Conversation

miniksa
Copy link
Member

@miniksa miniksa commented May 27, 2020

Summary of the Pull Request

Restores proper line drawing during IME operations in conhost

PR Checklist

Detailed Description of the Pull Request / Additional comments

  • Changed ConsoleImeInfo::s_ConvertToCells to be less confusing. It's doing about the same thing, but it's way easier to read now and the compiler/linker/optimizer should just be the same.
  • Edited Renderer::_PaintBufferOutputHelper to check each attribute for line drawing characters as the right half of a two-col character might have different line drawing characters than the left-half.

Validation Steps Performed

  • Manual operation of IME in conhost with Japanese IME.
  • Manual operation of IME in conhost with Chinese IME.
  • Manual operation of IME in conhost with Chinese (Traditional) IME.
  • Manual operation of IME in conhost with and Korean IME. - @leonMSFT says Korean doesn't work this way. But Korean is broken worse in that it's not showing suggestions at all. Filing new bug. Korean IME suggestions don't appear #6227
  • Validated against API-filling calls through SetConsoleTextAttribute per @j4james's sample code

@ghost ghost added Area-Interaction Interacting with the vintage console window (as opposed to driving via API or hooks) Area-Output Related to output processing (inserting text into buffer, retrieving buffer text, etc.) Area-Rendering Text rendering, emoji, complex glyph & font-fallback issues Issue-Bug It either shouldn't be doing this or needs an investigation. Product-Conhost For issues in the Console codebase labels May 27, 2020
@miniksa miniksa self-assigned this May 27, 2020
@miniksa
Copy link
Member Author

miniksa commented May 27, 2020

@j4james, this is my proposal.

…r character during the run and had to potentially skip an attribute and hide the lines.
@miniksa miniksa marked this pull request as ready for review May 27, 2020 19:34
@j4james
Copy link
Collaborator

j4james commented May 27, 2020

OK, this is much better than what I had. I ended up having to extend the OutputCellView and TextBufferCellIterator which is the part I hated the most (I need to look at the code again to see what made me think that was necessary). I was also concerned about the renderer having to draw the grid one character at a time, and wondering whether we might be able to optimise that a bit. But having that as a special case for wide characters does at least limit when that happens, so that's not too bad either.

I'm busy geeking out over the upcoming SpaceX launch at the moment, so I'll try and look at this in more detail later, but my initial impression is very positive.

@DHowett
Copy link
Member

DHowett commented May 27, 2020

I hate that this is possible. 😄

#6224 probably needs separate "line drawing runs" ...
that actually makes this way easier.

@miniksa
Copy link
Member Author

miniksa commented May 27, 2020

I hate that this is possible. 😄

#6224 probably needs separate "line drawing runs" ...
that actually makes this way easier.

Agreed. Each thing should probably be its own pass. If it can be efficient enough.

@j4james
Copy link
Collaborator

j4james commented May 28, 2020

I've had a chance to run some more tests now, and I'm not sure this is working as well as I had thought. I have a little test case that tries to render every combination of grid flag around a wide character, and that doesn't seem to work with this PR. This is my test code:

#include <windows.h>
#include <stdio.h>

void test(WORD attr)
{
  HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE);
  SetConsoleTextAttribute(handle, 0x07);
  printf(" ");
  SetConsoleTextAttribute(handle, 0x07 | attr);
  printf("\xE5\xA4\xA7");
  SetConsoleTextAttribute(handle, 0x07);
}

void main()
{
  SetConsoleOutputCP(CP_UTF8);
  printf("\n");
  test(COMMON_LVB_GRID_LVERTICAL);
  test(COMMON_LVB_GRID_HORIZONTAL);
  test(COMMON_LVB_GRID_RVERTICAL);
  test(COMMON_LVB_UNDERSCORE);
  test(COMMON_LVB_UNDERSCORE | COMMON_LVB_GRID_LVERTICAL);
  test(COMMON_LVB_GRID_LVERTICAL | COMMON_LVB_GRID_HORIZONTAL);
  test(COMMON_LVB_GRID_HORIZONTAL | COMMON_LVB_GRID_RVERTICAL);
  test(COMMON_LVB_GRID_RVERTICAL | COMMON_LVB_UNDERSCORE);
  test(COMMON_LVB_UNDERSCORE | COMMON_LVB_GRID_HORIZONTAL);
  test(COMMON_LVB_GRID_LVERTICAL | COMMON_LVB_GRID_RVERTICAL);
  test(COMMON_LVB_GRID_LVERTICAL | COMMON_LVB_GRID_RVERTICAL | COMMON_LVB_UNDERSCORE);
  test(COMMON_LVB_GRID_LVERTICAL | COMMON_LVB_GRID_RVERTICAL | COMMON_LVB_GRID_HORIZONTAL);
  test(COMMON_LVB_GRID_LVERTICAL | COMMON_LVB_GRID_RVERTICAL | COMMON_LVB_GRID_HORIZONTAL | COMMON_LVB_UNDERSCORE);
  printf("\n");
}

This is what I expected it to look like (more or less - not sure about the center grid lines, but I think that's a separate issue):

image

This is what I'm seeing with this PR:

image

I'm hoping maybe I've just screwed up the build somehow. Will do some more digging.

@j4james
Copy link
Collaborator

j4james commented May 29, 2020

One other thing I wanted to mention. It's not essential for this PR, but I thought while you're looking at this grid code, it might be a good time to get rid of COMMON_LVB_GRID_SINGLEFLAG. As far I could make out, it doesn't actually serve any purpose, and that would free up another bit for us to use in the attributes.

@miniksa
Copy link
Member Author

miniksa commented Jun 3, 2020

大 is

encoding code
UTF-8 0x35 0xa4 0xa7
UTF-16 0x59 0x27
Shift-JIS 0x91 0xe5

@miniksa
Copy link
Member Author

miniksa commented Jun 3, 2020

Conhost v1 with the scratch code:
image

Repaired OpenConsole on commit e1c757f:
image

@miniksa
Copy link
Member Author

miniksa commented Jun 3, 2020

One other thing I wanted to mention. It's not essential for this PR, but I thought while you're looking at this grid code, it might be a good time to get rid of COMMON_LVB_GRID_SINGLEFLAG. As far I could make out, it doesn't actually serve any purpose, and that would free up another bit for us to use in the attributes.

I went and read the code for this from conhostv1.

COMMON_LVB_GRID_SINGLEFLAG literally indicated to the IME output-buffer writer code that it needed to remove RVERTICAL from the left half of a two column character and LVERTICAL from the right half of a two column character. You know. Instead of determining that some other way and just stripping it out or only applying it to half the character.

So yeah, I think it can go away and/or be repurposed.

@miniksa miniksa added the Needs-Second It's a PR that needs another sign-off label Jun 3, 2020
@miniksa
Copy link
Member Author

miniksa commented Jun 3, 2020

I believe this is good for merge. It restores the behavior to match v1 conhost in both through-the-API and IME cases.

Copy link
Member

@zadjii-msft zadjii-msft left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, this looks sane, and there's enough comments that I could figure out what was going on here. Good enough for me 😄

@DHowett DHowett added the AutoMerge Marked for automatic merge by the bot when requirements are met label Jun 3, 2020
@ghost
Copy link

ghost commented Jun 3, 2020

Hello @DHowett!

Because this pull request has the AutoMerge label, I will be glad to assist with helping to merge this pull request once all check-in policies pass.

p.s. you can customize the way I help with merging this pull request, such as holding this pull request until a specific person approves. Simply @mention me (@msftbot) and give me an instruction to get started! Learn more here.

@ghost ghost merged commit 9b075e9 into master Jun 3, 2020
@ghost ghost deleted the dev/miniksa/803 branch June 3, 2020 22:21
@j4james
Copy link
Collaborator

j4james commented Jun 3, 2020

For the record this looked good to me too. Your solution turned out much simpler than what I thought would be required. 👍

@ghost
Copy link

ghost commented Jun 18, 2020

🎉Windows Terminal Preview v1.1.1671.0 has been released which incorporates this pull request.:tada:

Handy links:

This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Interaction Interacting with the vintage console window (as opposed to driving via API or hooks) Area-Output Related to output processing (inserting text into buffer, retrieving buffer text, etc.) Area-Rendering Text rendering, emoji, complex glyph & font-fallback issues AutoMerge Marked for automatic merge by the bot when requirements are met Issue-Bug It either shouldn't be doing this or needs an investigation. Needs-Second It's a PR that needs another sign-off Product-Conhost For issues in the Console codebase
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Lines are not drawn correctly during IME edit line operations
5 participants